package com.wanmait.baohan.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wanmait.baohan.mapper.DictionaryMapper;
import com.wanmait.baohan.mapper.StaffMapper;
import com.wanmait.baohan.mapper.WorkTemplateContentMapper;
import com.wanmait.baohan.mapper.WorkTemplateMapper;
import com.wanmait.baohan.pojo.DailyPlan;
import com.wanmait.baohan.pojo.Dictionary;
import com.wanmait.baohan.pojo.WorkTemplate;
import com.wanmait.baohan.pojo.WorkTemplateContent;
import com.wanmait.baohan.service.WorkTemplateService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author 打豆豆
 * @version 1.0
 * @date 2021/2/12 14:39
 * @description:
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class WorkTemplateServiceImpl implements WorkTemplateService {

    @Resource
    private WorkTemplateMapper workTemplateMapper;
    @Resource
    private WorkTemplateContentMapper workTemplateContentMapper;
    @Resource
    private StaffMapper staffMapper;
    @Resource
    private DictionaryMapper dictionaryMapper;

    @Override
    public void insert(WorkTemplate object) {
        workTemplateMapper.insertSelective(object);
        WorkTemplateContent workTemplateContent = new WorkTemplateContent();
        workTemplateContent.setWorkTemplateId(object.getId());
        workTemplateContentMapper.insert(workTemplateContent);
    }

    @Override
    public void delete(Integer id) {

    }

    @Override
    public void delete(String ids) {

    }

    @Override
    public void update(WorkTemplate object) {

    }

    @Override
    public WorkTemplate findById(Integer id) {
        return null;
    }

    @Override
    public List<WorkTemplate> findAll() {
        return workTemplateMapper.selectList(null);
    }

    @Override
    public List<WorkTemplate> findAll(WorkTemplate object) {
        return null;
    }

    @Override
    public PageInfo<WorkTemplate> findPage(int pageNum) {
        return null;
    }

    @Override
    public PageInfo<WorkTemplate> findPage() {
        return null;
    }

    @Override
    public PageInfo<WorkTemplate> findPage(int pageNum, WorkTemplate object) {
        return null;
    }

    @Override
    public PageInfo<WorkTemplate> findPage(WorkTemplate object) {
        return null;
    }

    /**
     * hxn
     * @param page
     * @param limit
     * @return
     * 获取所有的工作模板
     */
    @Override
    public PageInfo<WorkTemplate> SelectAllWorkTemplate(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<WorkTemplate> workTemplates = workTemplateMapper.selectList(null);
        workTemplates.forEach(workTemplate -> {
            workTemplate.setDrafter(staffMapper.findOneById(workTemplate.getDrafterId()));
            workTemplate.setReviewer(staffMapper.findOneById(workTemplate.getReviewerId()));
            QueryWrapper queryWrapper = new QueryWrapper<Dictionary>();
            queryWrapper.select("`key`","`value`","dictionary_type_id");
            queryWrapper.eq("dictionary_type_id", 36);
            queryWrapper.eq("`key`", workTemplate.getTemplateType());
            workTemplate.setTemplateTypeName(dictionaryMapper.selectOne(queryWrapper).getValue());
        });
        PageInfo<WorkTemplate> pageInfo = new PageInfo<>(workTemplates, 7);
        return pageInfo;
    }
}
